import uniqueId from "@form-create/utils/lib/unique";
import { localeProps, makeRequiredRule } from "../../utils";

const label = "计数器";
const name = "inputNumber";

export default {
  icon: "icon-number",
  label,
  name,
  rule({ t }) {
    return {
      type: name,
      field: uniqueId(),
      title: t("components.inputNumber.name"),
      info: "",
      $required: false,
      props: {},
    };
  },
  props(_, { t }) {
    return localeProps(t, name + ".props", [
      makeRequiredRule(),
      {
        type: "select",
        field: "mode",
        title: "模式",
        value: "embed",
        options: [
          {
            label: "内嵌模式",
            value: "embed",
          },
          {
            label: "按钮模式",
            value: "button",
          },
        ],
      },
      {
        type: "input",
        field: "placeholder",
        title: "输入框提示文字",
      },
      {
        type: "inputNumber",
        field: "min",
        title: "设置计数器允许的最小值",
      },
      {
        type: "inputNumber",
        field: "max",
        title: "设置计数器允许的最大值",
      },
      {
        type: "inputNumber",
        field: "step",
        title: "计数器步长",
        props: {
          min: 0,
        },
      },
      {
        type: "switch",
        field: "stepStrictly",
        title: "是否只能输入 step 的倍数",
      },
      {
        type: "switch",
        field: "disabled",
        title: "是否禁用",
      },
      {
        type: "switch",
        field: "readonly",
        title: "是否只读",
      },
    ]);
  },
};
